﻿package mortal.game.view.guild.tabpanel
{
    import Message.Client.*;
    import Message.DB.Tables.*;
    import Message.Game.*;
    import com.gengine.utils.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.daily.*;
    import mortal.game.view.guild.cellrender.*;
    import mortal.mvc.core.*;

    public class GuildBustlingPanel extends GuildBasePanel
    {
        private var _curWeekNum:BitmapNumberText;
        private var _lastWeekNum:BitmapNumberText;
        private var _bar:BaseProgressBar;
        private var _nextTargetNum:GTextFiled;
        private var _time:SecTimerView;
        private var _lastWeekTxt:GTextFiled;
        private var _rewardInfo:GTextFiled;
        private var _rewardBtn:GLoadingButton;
        private var _rewardItem1:GuildBustlingRewardsItem;
        private var _rewardItem2:GuildBustlingRewardsItem;
        private var _rewardItem3:GuildBustlingRewardsItem;
        private var _rewardItem4:GuildBustlingRewardsItem;
        private var _list:GTileList;

        public function GuildBustlingPanel()
        {
            super(ResFileConst.GuildBustlingPanel);
            return;
        }// end function

        private function onClickReward(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildGetActivityReward));
            return;
        }// end function

        private function get offset() : int
        {
            var _loc_1:int = 0;
            var _loc_3:TGuildActivityConfig = null;
            var _loc_2:* = Cache.instance.guild.selfGuildInfo.baseInfo.activity;
            var _loc_4:int = 1;
            while (_loc_4 <= 4)
            {
                
                _loc_3 = GuildActivityConfig.instance.getItemById(_loc_4);
                if (_loc_2 < _loc_3.guildActivity)
                {
                    _loc_1 = _loc_3.guildActivity - _loc_2;
                    break;
                }
                _loc_4++;
            }
            return _loc_1;
        }// end function

        private function get lastWeekRewardInfo() : String
        {
            var _loc_3:TGuildActivityConfig = null;
            var _loc_4:TGuildActivityConfig = null;
            var _loc_6:ItemInfo = null;
            var _loc_7:String = null;
            var _loc_1:String = "";
            var _loc_2:* = Cache.instance.guild.selfGuildInfo.baseInfo.lastWeekActivity;
            var _loc_5:int = 1;
            while (_loc_5 <= 4)
            {
                
                _loc_3 = GuildActivityConfig.instance.getItemById(_loc_5);
                _loc_4 = GuildActivityConfig.instance.getItemById((_loc_5 + 1));
                if (_loc_4 == null && _loc_2 >= _loc_3.guildActivity || _loc_2 >= _loc_3.guildActivity && _loc_2 < _loc_4.guildActivity)
                {
                    _loc_6 = ItemConfig.instance.getConfig(int(_loc_3.guildItemReward));
                    _loc_7 = HTMLUtil.addColor(_loc_6.name + "*1", ColorConfig.instance.getItemColorString(_loc_6.color));
                    _loc_1 = Language.getStringByParam(70483, _loc_7, _loc_3.guildCoinReward, _loc_3.guildGoldReward);
                    break;
                }
                _loc_5++;
            }
            return _loc_1;
        }// end function

        private function get leftTime() : Number
        {
            var _loc_3:int = 0;
            var _loc_1:* = ClockManager.instance.nowDate;
            var _loc_2:* = _loc_1.day == 0 ? (7) : (_loc_1.day);
            var _loc_4:* = 7 - _loc_2;
            var _loc_5:* = 24 - _loc_1.hours - 1;
            var _loc_6:* = 60 - _loc_1.minutes - 1;
            var _loc_7:* = 60 - _loc_1.seconds;
            return _loc_4 * 24 * 60 * 60 + _loc_5 * 60 * 60 + _loc_6 * 60 + _loc_7;
        }// end function

        override public function update() : void
        {
            var _loc_1:* = Cache.instance.guild.selfGuildInfo.baseInfo;
            var _loc_2:* = this.lastWeekRewardInfo;
            this._nextTargetNum.htmlText = Language.getStringByParam(70480, this.offset);
            this._curWeekNum.text = _loc_1.activity.toString();
            this._lastWeekNum.text = _loc_1.lastWeekActivity.toString();
            this._lastWeekTxt.htmlText = Language.getStringByParam(70485, this._lastWeekNum.text);
            this._rewardInfo.htmlText = _loc_2;
            this._bar.setValue(_loc_1.activity, GuildActivityConfig.instance.maxGuildActivity);
            if (_loc_2 == "" || Cache.instance.guild.selfGuildInfo.selfInfo.getReward == 1)
            {
                this._rewardBtn.filterEnabled = false;
            }
            else
            {
                this._rewardBtn.filterEnabled = true;
            }
            var _loc_3:int = 1;
            while (_loc_3 <= 4)
            {
                
                GuildBustlingRewardsItem(this["_rewardItem" + _loc_3]).data = GuildActivityConfig.instance.getItemById(_loc_3);
                _loc_3++;
            }
            return;
        }// end function

        override public function layoutUI() : void
        {
            if (isDisposed)
            {
                return;
            }
            UIFactory.bg(8, 60, 540, 254, this);
            UIFactory.bg(550, 60, 178, 254, this);
            UIFactory.bg(8, 317, 721, 215, this);
            UIFactory.gBitmap(ImagesConst.GuildBustling1, 35, 65, this);
            UIFactory.gBitmap(ImagesConst.GuildBustlingTxt2, 178, 128, this);
            UIFactory.gBitmap(ImagesConst.GuildBustlingTxt7, 590, 75, this);
            UIFactory.gBitmap(ImagesConst.RoleCombatBg, 560, 80, this);
            this._lastWeekTxt = UIFactory.gTextField("", 552, 139, 178, 60, this, GlobalStyle.textFormatHuang2.center());
            this._lastWeekTxt.multiline = true;
            this._lastWeekTxt.wordWrap = true;
            this._rewardInfo = UIFactory.gTextField("", 580, 180, 150, 80, this);
            this._rewardInfo.multiline = true;
            this._rewardInfo.wordWrap = true;
            this._lastWeekNum = UIFactory.bitmapNumberText(639, 98, "GuildCopyNum.png", 24, 32, -6, this, 9, BitmapNumberText.Mid);
            this._curWeekNum = UIFactory.bitmapNumberText(94, 105, "GuildCopyNum.png", 24, 32, -6, this, 9, BitmapNumberText.Mid);
            this._bar = UICompomentPool.getUICompoment(BaseProgressBar);
            this._bar.setBg(ImagesConst.VipProgressBg, false, 320, 30);
            this._bar.setProgress(ImagesConst.VipProgress, false, 21, 8, 275, 14);
            this._bar.setLabel(BaseProgressBar.ProgressBarTextNumber, 125, 5, 75, 8);
            UIFactory.setObjAttri(this._bar, 195, 75, -1, -1, this);
            this._nextTargetNum = UIFactory.gTextField(Language.getStringByParam(70480, 30), 235, 102, 250, 20, this, GlobalStyle.textFormatBai, true);
            this._time = UIFactory.secTimeView(Language.getString(70481), 355, 124, 200, 40, this, GlobalStyle.textFormatBai.setSize(16));
            this._time.setLeftTime(this.leftTime);
            this._rewardBtn = UIFactory.gLoadingButton(ResFileConst.DailyRewardBtn, 588, 266, 103, 40, this);
            this._rewardItem1 = UIFactory.getUICompoment(GuildBustlingRewardsItem, 10, 160, null, ImagesConst.GuildBustling2, 0);
            this._rewardItem1.titleBgName = ImagesConst.GuildBustling4;
            this._rewardItem2 = UIFactory.getUICompoment(GuildBustlingRewardsItem, 144, 159, null, ImagesConst.GuildBustling3, 0);
            this._rewardItem2.titleBgName = ImagesConst.GuildBustling3;
            this._rewardItem3 = UIFactory.getUICompoment(GuildBustlingRewardsItem, 278, 159, null, ImagesConst.GuildBustling3, 0);
            this._rewardItem3.titleBgName = ImagesConst.GuildBustling3;
            this._rewardItem4 = UIFactory.getUICompoment(GuildBustlingRewardsItem, 412, 159, null, ImagesConst.GuildBustling4, -1);
            this._rewardItem4.titleBgName = ImagesConst.GuildBustling2;
            this._rewardItem4.offsetX = -1;
            this.addChild(this._rewardItem1);
            this.addChild(this._rewardItem2);
            this.addChild(this._rewardItem3);
            this.addChild(this._rewardItem4);
            this._list = UIFactory.tileList(12, 322, 715, 210, this);
            this._list.setStyle("cellRenderer", GuildBustlingRenderer);
            this._list.columnWidth = 350;
            this._list.rowHeight = 105;
            this._list.direction = GBoxDirection.VERTICAL;
            this._list.dataProvider = new DataProvider(DailyUtil.getDataByGroup(EDailyType._EDailyTypeGuild));
            this._rewardBtn.configEventListener(MouseEvent.CLICK, this.onClickReward);
            UIFactory.gTextField("", 590, 75, 100, 100, this).toolTipData = Language.getString(70627);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            return;
        }// end function

    }
}
